import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    // path: '/home/:id',
    path: '/home/:id',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/child',
        component: ()=>import('../views/Son.vue')
      }
    ]
  },
  {
    path: '/layout',
    name: 'Layout',
    component: ()=>import('../views/element/Layout.vue')
  },
  {
    path: '/pop',
    name: 'Pop',
    component: ()=>import('../views/element/Pop.vue')
  },
  {
    path: '/table',
    name: 'Table',
    component: ()=>import('../views/element/Table.vue')
  },
  {
    path: '/form',
    name: 'Form',
    component: ()=>import('../views/element/Form.vue')
  },
  {
    path: '/',
    redirect: '/pop'
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})

//导航守卫  进入路由时获取token或判断用户的权限

router.beforeEach((to, from, next)=>{
  console.log(to.path)  //每一次进入路由前输入路径
  next()
})


export default router
